import Vue from 'vue';
import cookieConfig from '@/config/cookie';

/* #ifdef  MP-WEIXIN */
import Cookie from 'weapp-cookie';
/* #endif */

/* #ifndef MP-WEIXIN */
import Cookie from 'js-cookie';
/* #endif */

export function setCookie(name, value, expiredays,domain=cookieConfig.mp_domain) {
 
  /* #ifdef  MP-WEIXIN */
  let maxAge = expiredays * 24 * 60 * 60; // 换算秒
  return Cookie.set(name, value, {maxAge:expiredays?maxAge:0,domain});
  /* #endif */
  
  /* #ifndef MP-WEIXIN */
  return Cookie.set(name, value, {expires:expiredays||0});
  /* #endif */
  
}
export function getCookie(name) {
  return Cookie.get(name);
}
export function delCookie(name) {
  return Cookie.remove(name);
}

Vue.prototype.setCookie = setCookie;
Vue.prototype.getCookie = getCookie;
Vue.prototype.delCookie = delCookie;


export function getToken() {
  return getCookie(cookieConfig.tokenKey);
}

export function setToken(token) {
  return setCookie(cookieConfig.tokenKey, token,cookieConfig.expiredays);  
}

export function removeToken() {
  return Cookie.remove(cookieConfig.tokenKey);
}

